import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    path:'/',
    component:() => import('../views/login')
  },
  {
    path: '/',
    name: 'layout',
    redirect:'/homePage',
    component: () => import('../views/layout'),
    children:[
      {
        path:'homePage',
        meta:{title:'首页',index:'1'},
        component:() => import('../views/homePage')
      },
      {
        path:'totalSheet',
        meta:{title:'公厕总表',index:'2-1'},
        component:() => import('../views/toiletAccount/totalSheet')
      },
      {
        path:'toiAccount',
        meta:{title:'公厕台账',index:'2-2'},
        component:() => import('../views/toiletAccount/toiAccount')
      },
      {
        path:'toiEquip',
        meta:{title:'公厕设备管理',index:'3-1'},
        component:() => import('../views/equipToi/toiEquip')
      },
      {
        path:'equMonitor',
        meta:{title:'设备实时监测',index:'3-2'},
        component:() => import('../views/equipToi/equMonitor')
      },
      {
        path:'toiAlarm',
        meta:{title:'公厕报警记录',index:'3-3'},
        component:() => import('../views/equipToi/toiAlarm')
      },
      {
        path:'GISAdmin',
        meta:{title:'公厕GIS管理',index:'4-1'},
        component:() => import('../views/GISAdmin/mapbox')
      },
      {
        path:'anotherToi',
        component:() => import('../views/anotherToi')
      },
      {
        path:'eventsReport',
        component:() => import('../views/eventsReport')
      }
    ]
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

router.beforeEach((to, from, next) => {
  let Authorization = localStorage.getItem('sessionId')
  if(Authorization || to.fullPath=="/" ){
    next()
  }else{
    next()
      router.push({
        path:'/'
    })
  }
})


export default router
